package edu.java.texbooks.scjp.threads.test17;

/**
 * Here we test throwing of <code>Interrupted Exception</code> when we call
 * <code>interrupt()</code> method of a <code>sleeping</code>thread.
 * 
 */
public class TestInterruptedException {
	public static void main(String[] args) {
		System.out.println(Thread.currentThread().getName()
				+ " thread starts.....");

		// create some thread "t" which will be interrupted by the main thread.
		MyRunnable mr = new MyRunnable();
		Thread t = new Thread(mr, "cecoThread");

		// starts "t" thread
		t.start();

		// main thread goes to sleep for a while because we want "t" thread to
		// start
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		System.out.println(Thread.currentThread().getName()
				+ " thread continues because " + t.getName() + " is sleeping."
				+ Thread.currentThread().getName()
				+ " thread goes to interrupt " + t.getName() + ".");

		// main thread interrupts the sleeping thread "t" which will
		// throw Interrupted Exception
		t.interrupt();

	}
}
